/**
 * Created by Administrator on 2016/9/27.
 */
(function($){
    $(function(){

         var sAttr=JSON.parse(getCookie("attr")),
             oCenter4 = $(".map-bt"),
             oMap = $(".map-bt2"),
             sUtm = "";
             if(sAttr.length==0){
                 oMap.css({display:"none"});
                 oCenter4.css({display:"block"});
             }else{
                 oMap.css({display:"block"});
                 oCenter4.css({display:"none"});
              for(var i=0; i < sAttr.length; i++) {
               var price=((sAttr[0].attrNum)*(sAttr[0].attrPrice)).toFixed(2);
                  sUtm +='<li><div class="btz"><div class="center4-1"><input type="checkbox" checked="checked"> <img src="'+sAttr[0].attrSrc+'"></div><div class="center4-2"><a href="javascript:;" class="aes">'+sAttr[0].attrName+'</a></div><div class="center4-3">￥<span>'+sAttr[0].attrPrice+'</span></div><div class="center4-4"><a href="javascript:;" > - </a><input class="inpr" type="text" value="'+sAttr[0].attrNum+'" name="na" style="background:#fff;border:1px solid #ccc;" disabled="disabled"><a href="javascript:;"> + </a></div><div class="center4-5">￥<span class="ss">'+price+'</span></div><div class="center4-6"><a href="javascript:;" class="delete">删除</a></div></div></li>'
              }
              $(".map-bt2 ul").html(sUtm);
              $(".bt2-cent1 .spaq1").html(price);
              $(".span2 b").html(sAttr[0].attrNum);
              $(".em1").html(parseInt(price));
              $(".em2").html(parseInt(price));
            }


           var  oChec= $(".chec"),
                oSpa= $(".bt2-cent1 .spaq1"),
                Btcen=$(".bt2-center3");

          oChec.click(function(){
              if((oSpa.css("display")=="block")&&(Btcen.css("display")=="block")){
                  oSpa.css({display:"none"});
                  Btcen.css({display:"none"})
              }else{
                  oSpa.css({display:"block"});
                  Btcen.css({display:"block"})
              }


        })
           //点击更换
           var number=sAttr[0].attrNum,
               price2=sAttr[0].attrPrice,
               centA=$(".center4-4 a"),
               iIdenxp= 0;
          centA.click(function(){
               iIdenxp=centA.index($(this));
              if(iIdenxp==0){
                  number--;
                  if(number<1){
                      number=1
                  }
                  $(".inpr").val(number);
                  $(".span2 b").html(number);
                  $(".spaq1").html((number*price2).toFixed(2));
                  $(".em1").html((number*price2).toFixed(2));
                  $(".em2").html((number*price2).toFixed(2));
                  $(".ss").html((number*price2).toFixed(2));
               }else{
                  number++;
                  $(".inpr").val(number);
                  $(".span2 b").html(number);
                  $(".spaq1").html((number*price2).toFixed(2));
                  $(".em1").html((number*price2).toFixed(2));
                  $(".em2").html((number*price2).toFixed(2));
                  $(".ss").html((number*price2).toFixed(2));

              }

          })

           $(".suan").on("click",function(){
               setCookie("inpr",$(".inpr").val(),7,"/");
           });


        var Delete= $(".delete");
        Delete.click(function(){
            setCookie("attr",JSON.stringify([]),30,"/");
            oMap.css({display:"none"});
            oCenter4.css({display:"block"});
        })


    })

})(jQuery)